package org.dromara.netbar.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.netbar.domain.vo.NetbarMemberBalanceLogVo;
import org.dromara.netbar.domain.bo.NetbarMemberBalanceLogBo;
import org.dromara.netbar.service.INetbarMemberBalanceLogService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 余额流水表
 *
 * @author Lion Li
 * @date 2025-07-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/netbar/memberBalanceLog")
public class NetbarMemberBalanceLogController extends BaseController {

    private final INetbarMemberBalanceLogService netbarMemberBalanceLogService;

    /**
     * 查询余额流水表列表
     */
    @SaCheckPermission("netbar:memberBalanceLog:list")
    @GetMapping("/list")
    public TableDataInfo<NetbarMemberBalanceLogVo> list(NetbarMemberBalanceLogBo bo, PageQuery pageQuery) {
        return netbarMemberBalanceLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出余额流水表列表
     */
    @SaCheckPermission("netbar:memberBalanceLog:export")
    @Log(title = "余额流水表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NetbarMemberBalanceLogBo bo, HttpServletResponse response) {
        List<NetbarMemberBalanceLogVo> list = netbarMemberBalanceLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "余额流水表", NetbarMemberBalanceLogVo.class, response);
    }

    /**
     * 获取余额流水表详细信息
     *
     * @param memberBalanceId 主键
     */
    @SaCheckPermission("netbar:memberBalanceLog:query")
    @GetMapping("/{memberBalanceId}")
    public R<NetbarMemberBalanceLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long memberBalanceId) {
        return R.ok(netbarMemberBalanceLogService.queryById(memberBalanceId));
    }

    /**
     * 新增余额流水表
     */
    @SaCheckPermission("netbar:memberBalanceLog:add")
    @Log(title = "余额流水表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NetbarMemberBalanceLogBo bo) {
        return toAjax(netbarMemberBalanceLogService.insertByBo(bo));
    }

    /**
     * 修改余额流水表
     */
    @SaCheckPermission("netbar:memberBalanceLog:edit")
    @Log(title = "余额流水表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NetbarMemberBalanceLogBo bo) {
        return toAjax(netbarMemberBalanceLogService.updateByBo(bo));
    }

    /**
     * 删除余额流水表
     *
     * @param memberBalanceIds 主键串
     */
    @SaCheckPermission("netbar:memberBalanceLog:remove")
    @Log(title = "余额流水表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{memberBalanceIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] memberBalanceIds) {
        return toAjax(netbarMemberBalanceLogService.deleteWithValidByIds(List.of(memberBalanceIds), true));
    }
}
